/**
 * 功能描述
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	
	var QuestionnaireProfile_Events=require("../handler/QuestionnaireProfile_Events")
    var IntentionRegister_Events=require("../handler/Returnvisit_Events")
    var intentionregister_Props = require("../constant/returnvisit_Props");
    
    module.exports = {
		
    	recordEdit : function(widget,data,disabled,type){
        	widget.get("form").reset();
        	widget.get("form").setDisabled(disabled);
			widget.show([".J-tab"]).hide([".J-recordgrid",".J-grid"]);
			widget.get("subnav").hide(["visitTime","status","intention","productType","product","search"]).show(["return","save"]);							
			if(disabled){
        		widget.get("subnav").hide(["save"]);
        	}
			widget.get("form").setData(data);
			IntentionRegister_Events.changeProduct(widget,data.productType.pkProductType);
			if(data.questionAnswerSheet){
				QuestionnaireProfile_Events.setQuestionaire(data.questionAnswerSheet,widget);
			}
//			IntentionRegister_Events.changeBirthday(widget,data.customer.personalInfo.birthday);
			/**
			 * 人员信息赋值
			 * 这垃圾代码……
			 */
			
			widget.get("form").setValue("product", data.productType.product);
			widget.get("form").setValue("pkCustomer",data.customer.pkCustomer);
			widget.get("form").setValue("customerVersion",data.customer.version);
			widget.get("form").setValue("personalInfo.name",data.customer.personalInfo.name);
			widget.get("form").setValue("personalInfo.sex",data.customer.personalInfo.sex);
			widget.get("form").setValue("personalInfo.idNumber",data.customer.personalInfo.idNumber);
			widget.get("form").setValue("personalInfo.birthday",data.customer.personalInfo.birthday);
			widget.get("form").setValue("personalInfo.mobilePhone",data.customer.personalInfo.mobilePhone);
			widget.get("form").setValue("personalInfo.houseRegister",data.customer.personalInfo.houseRegister);
			widget.get("form").setValue("personalInfo.address",data.customer.personalInfo.address);
			widget.get("form").setValue("personalInfo.electronicMail",data.customer.personalInfo.electronicMail);
			widget.get("form").setValue("organization",data.customer.organization.pkOrganization);
			widget.get("form").setValue("personalInfo.pkPersonalInfo",data.customer.personalInfo.pkPersonalInfo);
			widget.get("form").setValue("personalInfo.version",data.customer.personalInfo.version);
			widget.get("form").setValue("saleConsultant",data.saleConsultant.pkUser);
			widget.get("form").setValue("recordType",data.recordType.key);
			widget.get("form").setValue("wechat",data.customer.wechat);
			widget.get("form").setValue("qq",data.customer.qq);
			widget.get("form").setValue("zipCode",data.customer.zipCode);
		},
    		
		showReturnRecord : function(widget, datas, sCb){
			var obj = {
					"customer" : datas.pkCustomer,
					"returnVisitTime": datas.returnVisitTime,
//					"returnVisitTimeEnd": datas.returnVisitTime,
					"recordType" : "Return",
					fetchProperties : intentionregister_Props.recordGridFetchProperties	
			}
			aw.ajax({
				url : "api/customervisitrecord/query",
				data : obj,
				dataType : "json",
				success : function(data){
					sCb(data);
				}
			})
		},
		
		compareVisitDate : function(data, datas){
			if(datas.length ==1){
				return datas[0];
			}
			for(var i = 0; i < datas.length; i++){
				if(datas[i].visitDate == data.returnVisitTime){
					return datas[i];
				}
			}
		},
		
        showDetail : function(widget,data,disabled,type){
        	widget.get("form").reset();
        	widget.get("form").setDisabled(disabled);
			widget.show([".J-tab"]).hide([".J-grid"]);
			widget.get("subnav").hide(["visitTime","status","intention","productType","product","search"]).show(["return","save"]);							
			if(disabled){
        		widget.get("subnav").hide(["save"]);
        	}
			widget.get("profile").reset();
			widget.$(".J-other-answer").val("");
			widget.get("form").setValue("type",type);
//			IntentionRegister_Events.changeBirthday(widget,data.personalInfo.birthday);
			/**
			 * 人员信息赋值
			 * 这垃圾代码……
			 */
			//widget.get("form").setValue("product", data.productType.product);
			widget.get("form").setData(data);
			widget.get("form").setValue("product",data.productType.product);
			widget.get("form").setValue("pkCustomer",data.pkCustomer);
			widget.get("form").setValue("customerVersion",data.version);
			widget.get("form").setValue("personalInfo.name",data.personalInfo.name);
			widget.get("form").setValue("personalInfo.sex",data.personalInfo.sex);
			widget.get("form").setValue("personalInfo.idNumber",data.personalInfo.idNumber);
			widget.get("form").setValue("personalInfo.birthday",data.personalInfo.birthday);
			widget.get("form").setValue("personalInfo.mobilePhone",data.personalInfo.mobilePhone);
			widget.get("form").setValue("personalInfo.houseRegister",data.personalInfo.houseRegister);
			widget.get("form").setValue("personalInfo.address",data.personalInfo.address);
			widget.get("form").setValue("personalInfo.electronicMail",data.personalInfo.electronicMail);
			widget.get("form").setValue("organization",data.organization.pkOrganization);
			widget.get("form").setValue("personalInfo.pkPersonalInfo",data.personalInfo.pkPersonalInfo);
			widget.get("form").setValue("personalInfo.version",data.personalInfo.version);
			widget.get("form").setValue("saleConsultant",data.saleConsultant.pkUser);
			widget.get("form").setValue("wechat",data.wechat);
			widget.get("form").setValue("qq",data.qq);
			widget.get("form").setValue("zipCode",data.zipCode);
			//回访记录
			widget.get("form").setValue("recordType",type);
		},
    };
});
